package com.honglang.module.article.service;

import java.util.List;

import com.honglang.module.article.dao.ArticleCategoriesDao;
import com.honglang.module.article.dao.BlogArticleDao;
import com.honglang.module.article.entity.ArticleCategories;
import com.honglang.module.article.entity.BlogArticle;

public class ArticleCategoriesServiceImpl implements ArticleCategoriesService{
	
	private ArticleCategoriesDao articleCategoriesDao;

	private BlogArticleDao blogArticleDao;
	
	/**
	 * save article category
	 * @param articleCategories
	 * @return
	 */
	public ArticleCategories save(ArticleCategories articleCategories){
		
		return this.articleCategoriesDao.merge(articleCategories);
	}
	
	
	/**
	 * delete ArticleCategories;
	 * @param articleCategories
	 */
	public void delete(ArticleCategories articleCategories){
		List<BlogArticle> blogArticleList = this.blogArticleDao.getBlogArticleByArticleCategoryId(articleCategories.getId());
		if(blogArticleList.size() > 0 ){
			this.blogArticleDao.deleteAll(blogArticleList);
		}
		this.articleCategoriesDao.delete(articleCategories);
	
	}
	
	
	
	
	
	/**
	 * Get All the articleCategories entities;
	 * @return
	 */
	public List<ArticleCategories> getAll(){
		
		return this.articleCategoriesDao.getAll();
	}
	
	
	/**
	 * Get the articleCategory By Id
	 * @param articleCategoryId
	 * @return
	 */
	public ArticleCategories getById(Integer articleCategoryId){
		
		return this.articleCategoriesDao.getById(articleCategoryId);
	}
	
	
	
	/**
	 * get articleCategory by categoryname, if not exist return null;
	 * @param articleCategoryName
	 * @return
	 */
	public ArticleCategories getByCategoryName(String articleCategoryName){
		
		return this.articleCategoriesDao.getByCategoryName(articleCategoryName);
	}
	
	
	
	/**
	 * is articleCategories named 'articleCatetoryName' exist ? return true if it's exists ,else return false;
	 * @param articleCategoryName
	 * @return
	 */
	public boolean isCategoryNameExist(String articleCategoryName){
		
		return null == this.articleCategoriesDao.getByCategoryName(articleCategoryName)? false :true;
	}
	
	
	
	
	
	public ArticleCategoriesDao getArticleCategoriesDao() {
		return articleCategoriesDao;
	}

	public void setArticleCategoriesDao(ArticleCategoriesDao articleCategoriesDao) {
		this.articleCategoriesDao = articleCategoriesDao;
	}


	public BlogArticleDao getBlogArticleDao() {
		return blogArticleDao;
	}


	public void setBlogArticleDao(BlogArticleDao blogArticleDao) {
		this.blogArticleDao = blogArticleDao;
	}
	
	
}
